<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>注册</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" th:href="@{/plugins/bootstrap/css/bootstrap.min.css}"/>
    <link rel="stylesheet" th:href="@{/plugins/font-awesome/font-awesome.min.css}"/>
    <link rel="stylesheet" th:href="@{/plugins/iCheck/square/blue.css}"/>
    <link rel="stylesheet" th:href="@{/common/css/common.css}"/>
    <link rel="stylesheet" th:href="@{/common/css/login.css}"/>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
            </button>
            <a class="logo-a" th:href="@{/}"><img th:src="@{/img/logo.png}" alt="logo"></a>
        </div>
    </div>
</nav>
<div class="login-content">
    <div class="login-bg"></div>
    <div class="login-box">
        <form id="registerForm" class="login-form">
            <div class="login-title">用户注册</div>
            <div class="form-group has-feedback">
                <input type="text" name="username"  class="form-control" placeholder="输入用户名" >
                <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
            </div>
            <div class="form-group has-feedback">
                <input name="password" type="password" class="form-control" placeholder="输入密码">
                <span class="glyphicon glyphicon-lock form-control-feedback"></span>
            </div>
            <div class="form-group has-feedback">
                <input name="confirmPassword" type="password" placeholder="输入确认密码" class="form-control">
                <span class="glyphicon glyphicon-lock form-control-feedback"></span>
            </div>
            <div class="form-group">
                <div class="code-content">
                    <input type="text" name="verification" id="verification" class="form-control code-input" placeholder="输入验证码">
                </div>
                <img id="verificationCode" th:src="@{/verificationCode}" class="pointer code-img">
            </div>
            <div class="row">
                <div class="col-xs-8">
                    <div class="checkbox icheck">
                        <label style="padding: 0">
                            <input type="checkbox" id="agreeItems" checked  value="1"> 我同意<a href="#">用户注册条款</a>
                        </label>
                    </div>
                </div>
                <div class="col-xs-4">
                    <button id="registerBtn" type="button" class="btn btn-primary btn-block btn-flat">注册</button>
                </div>
            </div>
            <div class="mt-20">
                已有账户？<a th:href="@{/login}">点此登录</a>
            </div>
        </form>
    </div>

</div>
<div class="copyright-light copyright-section">
    <p>Copyright © 2020. All rights reserved.</p>
</div>

<script th:inline="javascript"> var ctx = [[@{/}]]; </script>
<script th:src="@{/plugins/jquery/jquery.min.js}"></script>
<script th:src="@{/plugins/bootstrap/js/bootstrap.min.js}"></script>
<script th:src="@{/plugins/layer/layer.min.js}"></script>
<script th:src="@{/plugins/iCheck/icheck.min.js}"></script>
<script th:src="@{/plugins/jquery-validation/jquery.validate.min.js}"></script>
<script th:src="@{/plugins/jquery-validation/messages_zh.min.js}"></script>
<script th:src="@{/common/js/core.js}"></script>
<script>
    $(function () {
        $('input').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%'
        });

        $(".code-img").on('click', function () {
            $(this).attr('src', ctx + 'verificationCode?' + Math.floor(Math.random() * 100));
        });

        $("#registerBtn").on('click', function () {
            if (!$("#registerForm").validate().form()) {
                return;
            }
            $.ajax({
                type: "POST",
                url: ctx + "register",
                data: $("#registerForm").serialize(),
                dataType: "json",
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {
                            offset:'30%',
                            time:800
                        }, function(){
                            window.location.href = ctx + "login";
                        });
                    }else {
                        layer.msg(data.msg);
                        $("#verificationCode").click();
                    }
                }
            });
        });
	
        // 键盘按下Enter键事件监听
        $(document).keyup(function(event){
            if(event.keyCode == 13){
                $("#registerBtn").click();
            }
        });
    })
</script>
</body>
</html>